﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using YuuzleComic.Model;
using YuuzleComic.DALFactory;
using YuuzleComic.IDAL;
namespace YuuzleComic.BLL
{
	/// <summary>
	/// comics
	/// </summary>
	public partial class comics
	{
		private readonly Icomics dal=DataAccess.Createcomics();
		public comics()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int id)
		{
			return dal.Exists(id);
		}

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string mhmc)
        {
            return dal.Exists(mhmc);
        }

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(YuuzleComic.Model.comics model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(YuuzleComic.Model.comics model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int id)
		{
			
			return dal.Delete(id);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string idlist )
		{
			return dal.DeleteList(idlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public YuuzleComic.Model.comics GetModel(int id)
		{
			
			return dal.GetModel(id);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public YuuzleComic.Model.comics GetModelByCache(int id)
		{
			
			string CacheKey = "comicsModel-" + id;
			object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(id);
					if (objModel != null)
					{
						int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
						Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (YuuzleComic.Model.comics)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<YuuzleComic.Model.comics> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<YuuzleComic.Model.comics> DataTableToList(DataTable dt)
		{
			List<YuuzleComic.Model.comics> modelList = new List<YuuzleComic.Model.comics>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				YuuzleComic.Model.comics model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new YuuzleComic.Model.comics();
					if(dt.Rows[n]["id"].ToString()!="")
					{
						model.id=int.Parse(dt.Rows[n]["id"].ToString());
					}
					if(dt.Rows[n]["classid"].ToString()!="")
					{
						model.classid=int.Parse(dt.Rows[n]["classid"].ToString());
					}
                    model.mhmc = dt.Rows[n]["mhmc"].ToString();
                    model.mhbm = dt.Rows[n]["mhbm"].ToString();
                    model.mhtc = dt.Rows[n]["mhtc"].ToString();
					if(dt.Rows[n]["zzid"].ToString()!="")
					{
						model.zzid=int.Parse(dt.Rows[n]["zzid"].ToString());
					}
					if(dt.Rows[n]["dqid"].ToString()!="")
					{
						model.dqid=int.Parse(dt.Rows[n]["dqid"].ToString());
					}
					model.zm=dt.Rows[n]["zm"].ToString();
					if(dt.Rows[n]["zt"].ToString()!="")
					{
						if((dt.Rows[n]["zt"].ToString()=="1")||(dt.Rows[n]["zt"].ToString().ToLower()=="true"))
						{
						model.zt=true;
						}
						else
						{
							model.zt=false;
						}
					}
					model.mhfm=dt.Rows[n]["mhfm"].ToString();
					if(dt.Rows[n]["hits_d"].ToString()!="")
					{
						model.hits_d=int.Parse(dt.Rows[n]["hits_d"].ToString());
					}
					if(dt.Rows[n]["hits_d_d"].ToString()!="")
					{
						model.hits_d_d=DateTime.Parse(dt.Rows[n]["hits_d_d"].ToString());
					}
					if(dt.Rows[n]["hits_w"].ToString()!="")
					{
						model.hits_w=int.Parse(dt.Rows[n]["hits_w"].ToString());
					}
					if(dt.Rows[n]["hits_w_d"].ToString()!="")
					{
						model.hits_w_d=int.Parse(dt.Rows[n]["hits_w_d"].ToString());
					}
					if(dt.Rows[n]["hits_m"].ToString()!="")
					{
						model.hits_m=int.Parse(dt.Rows[n]["hits_m"].ToString());
					}
					if(dt.Rows[n]["hits_m_d"].ToString()!="")
					{
						model.hits_m_d=DateTime.Parse(dt.Rows[n]["hits_m_d"].ToString());
					}
					if(dt.Rows[n]["hits"].ToString()!="")
					{
						model.hits=int.Parse(dt.Rows[n]["hits"].ToString());
					}
					model.mhjs=dt.Rows[n]["mhjs"].ToString();
					if(dt.Rows[n]["adddate"].ToString()!="")
					{
						model.adddate=DateTime.Parse(dt.Rows[n]["adddate"].ToString());
					}
					if(dt.Rows[n]["tj"].ToString()!="")
					{
						if((dt.Rows[n]["tj"].ToString()=="1")||(dt.Rows[n]["tj"].ToString().ToLower()=="true"))
						{
						model.tj=true;
						}
						else
						{
							model.tj=false;
						}
					}
					if(dt.Rows[n]["cjid"].ToString()!="")
					{
						model.cjid=int.Parse(dt.Rows[n]["cjid"].ToString());
					}
					model.cjitemid=dt.Rows[n]["cjitemid"].ToString();
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
        public DataSet GetList(int PageSize, int PageIndex, string strWhere)
        {
            return dal.GetList(PageSize, PageIndex, strWhere);
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetViewList(string fldName, int isDesc, int PageSize, int PageIndex, string strWhere)
        {
            return dal.GetViewList(fldName, isDesc, PageSize, PageIndex, strWhere);
        }
		#endregion  Method
	}
}

